﻿using SigowayCommonLib;
using SigowayCommonLib.ADO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WarehouseManager.BL;
using WarehouseManager.Common;
using WarehouseManager.View;

namespace WarehouseManager
{
    public enum PatientSearchEnum
    {
        //按姓名
        Name,
        //按拼音
        Pinyin,
        //按编号
        Num
    }

    /// <summary>
    ///  患者信息,药品信息设定委托
    /// </summary>
    /// <param name="rowInfo"></param>
    public delegate void SetInfoCallBack(DataRow rowInfo);


    public partial class BillCreateForm : Form
    {
        //操作员ID
        private string _operatorID = string.Empty;

        private BillCreateBL blBillCreate;

        /// <summary>
        ///  一览数据源
        /// </summary>
        private DataTable datSource;

        /// <summary>
        ///  单据番号
        /// </summary>
        private long nCurrentBillNo;

        /// <summary>
        ///  当前日期
        /// </summary>
        private string strDateNow;

        private string strDataNowyyyyMMdd;

        /// <summary>
        ///  当前患者ID
        /// </summary>
        private string strCurOatientID;

        /// <summary>
        /// 画面单据号List
        /// </summary>
        private List<string> lstBillNoGUI;

        //关闭
        public Action CloseEvent;
        private BackgroundWorker m_BackgroundWorker;

        #region BillCreateForm
        /// <summary>
        ///  构造函数
        /// </summary>
        /// <param name="operatorID"></param>
        /// <param name="operatorName"></param>
        public BillCreateForm(string operatorID, string operatorName)
        {
            InitializeComponent();

            this._operatorID = operatorID;
            this.lblOperator.Text = operatorName;
            this.lblOpDate.Text = DateTimeUtil.GetCurrentDate();

        } 
        #endregion

        #region BillCreateForm_Load
        /// <summary>
        ///  画面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BillCreateForm_Load(object sender, EventArgs e)
        {
            try
            {
                Init();
            }
            catch (Exception ex)
            {
                MessageBoxHelp.ShowMsgError("初期启动失败!");
                LogManager.WriteLine("初期启动失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region Init
        /// <summary>
        ///  画面初期化
        /// </summary>
        private void Init()
        {
            this.blBillCreate = new BL.BillCreateBL();

            // 当前日期
            this.strDateNow = DateTimeUtil.GetCurrentDate();
            this.strDataNowyyyyMMdd = DateTime.Now.ToString("yyyyMMdd");

            //单据数
            this.nCurrentBillNo = this.blBillCreate.GetMaxBileNo(this.strDateNow);
            this.lstBillNoGUI = new List<string>();

            this.datSource = this.blBillCreate.CreateDataSource();
            this.datGridList.DataSource = this.datSource;

            //画面Data情况
            this.ClearPatientData();
            this.ClearDurgData();

            //非管理员账户，药品录入按钮不可见
            this.btnDrupSetting.Visible = IsAdmin();

            this.toolTip1.SetToolTip(this.txtDrugID, "请输入药品规格进行查询");

            this.txtPatientKey.Focus();
            #region BackgroundWorker
            m_BackgroundWorker = new BackgroundWorker();
            m_BackgroundWorker.WorkerReportsProgress = true;
            m_BackgroundWorker.WorkerSupportsCancellation = true;
            m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
            m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
            #endregion
        }

        private bool IsAdmin()
        {
            return this._operatorID == ConstInfo.Admin;
        }
        #endregion

        void DoWork(object sender, DoWorkEventArgs e)
        {
            #region Create Datatable For Test  施装时可以删除
            DataTable datTemp = new DataTable();
            //序号
            datTemp.Columns.Add("xuhao", typeof(string));
            //货号
            datTemp.Columns.Add(ConstInfo.COL_ARTNO, typeof(string));
            //品名
            datTemp.Columns.Add(ConstInfo.COL_DRUGNAME, typeof(string));
            //规格
            datTemp.Columns.Add(ConstInfo.COL_DRUGSPEC, typeof(string));
            //产地
            datTemp.Columns.Add(ConstInfo.COL_PRODUCEAREA, typeof(string));
            //数量
            datTemp.Columns.Add(ConstInfo.COL_DRUGCOUNT, typeof(string));
            //批号
            datTemp.Columns.Add("pihao");
            for (int nRowCount = 0; nRowCount < datSource.Rows.Count; nRowCount++)
            {
                DataRow dar = datTemp.NewRow();
                dar["xuhao"] = (nRowCount + 1).ToString();
                //货号
                dar[ConstInfo.COL_ARTNO] = datSource.Rows[nRowCount][ConstInfo.COL_ARTNO].ToString();
                //品名
                dar[ConstInfo.COL_DRUGNAME] = datSource.Rows[nRowCount][ConstInfo.COL_DRUGNAME].ToString();
                //规格
                dar[ConstInfo.COL_DRUGSPEC] = datSource.Rows[nRowCount][ConstInfo.COL_DRUGSPEC].ToString();
                //产地
                dar[ConstInfo.COL_PRODUCEAREA] = datSource.Rows[nRowCount][ConstInfo.COL_PRODUCEAREA].ToString();
                //数量
                dar[ConstInfo.COL_DRUGCOUNT] = datSource.Rows[nRowCount][ConstInfo.COL_DRUGCOUNT].ToString();
                //dar["pihao"] = nRowCount.ToString() + "生产批号~~~~~~~~";
                dar["pihao"] = "";
                datTemp.Rows.Add(dar);
            }
            List<string> lstTemp = new List<string>();
            lstTemp.Add(lblName.Text);
            lstTemp.Add(lblAddres.Text);
            lstTemp.Add(lblTel.Text);
            lstTemp.Add(DateTime.Now.ToString("yyyy-MM-dd"));
            lstTemp.Add(lblOperator.Text);
            lstTemp.Add("");
            #endregion
            Print print = new Print();
            int nBushu;
            if (!int.TryParse(txtBushu.Text, out nBushu))
            {
                nBushu = 1;
            }
            print.BuShu = nBushu;
            print.DoPrint(datTemp, lstTemp);
            print.DoPrintForPaient(datTemp, lstTemp);
        }

        void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBoxHelp.ShowMsgError("打印失败!");
                LogManager.WriteLine("打印失败!Exception={0}", e.Error);
            }
            else if (e.Cancelled)
            {
                MessageBoxHelp.ShowMsgWarning("打印取消");
            }
            else
            {
                MessageBoxHelp.ShowMsgInfor("打印完了");
            }
            this.Enabled = true;
            this.btnPrint.Enabled = true;
            this.btnPrint.Text = "打印送货单";
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (null == datSource || datSource.Rows.Count < 1)
            {
                MessageBoxHelp.ShowMsgWarning("没有可打印的信息");
                return;
            }
            this.Enabled = false;
            this.btnPrint.Enabled = false;
            this.btnPrint.Text = "打印中";
            m_BackgroundWorker.RunWorkerAsync();
        }

        #region BillCreateForm_FormClosed
        /// <summary>
        ///  画面关闭程序退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BillCreateForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (this.CloseEvent != null)
            {
                this.CloseEvent.Invoke();
            }
        } 
        #endregion

        #region btnPatientSetting_Click
        /// <summary>
        /// 患者信息设定画面打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPatientSetting_Click(object sender, EventArgs e)
        {
            PatientRegisterForm frmPatientRegister =
                new PatientRegisterForm(this.lblOperator.Text, this._operatorID, DateTime.Now.ToString("yyyy-MM-dd"));
            frmPatientRegister.ShowDialog();
            this.ClearPatientData();
            this.txtPatientKey.Focus();
        } 
        #endregion

        #region btnDrupSetting_Click
        /// <summary>
        /// 药品信息设定画面打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDrupSetting_Click(object sender, EventArgs e)
        {
            DrupRegisterForm frmDrupRegister =
                new DrupRegisterForm(this._operatorID, this.lblOperator.Text);
            frmDrupRegister.ShowDialog();
            this.ClearDurgData();
            this.txtDrugID.Focus();
        } 
        #endregion

        #region txtPatientKey_Validating
        /// <summary>
        ///  患者信息Validating
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtPatientKey_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                //未发生变化时，取消后续处理
                if (this.txtPatientKey.Tag != null && this.txtPatientKey.Text == this.txtPatientKey.Tag.ToString())
                {
                    return;
                }

                this.errorProvider.Clear();
                //患者信息清空时
                if (string.IsNullOrEmpty(this.txtPatientKey.Text))
                {
                    //患者信息清空
                    this.ClearPatientData();
                    return;
                }

                PatientSearchEnum searchEnum;
                if (this.radioBtnName.Checked)
                {
                    searchEnum = PatientSearchEnum.Name;
                }
                else if (this.radioBtnPinyin.Checked)
                {
                    searchEnum = PatientSearchEnum.Pinyin;
                }
                else
                {
                    searchEnum = PatientSearchEnum.Num;
                }
                //患者信息取得
                DataTable datPatientInfo = this.blBillCreate.GetPatientInfo(this.txtPatientKey.Text, searchEnum);
                if (datPatientInfo == null || datPatientInfo.Rows.Count == 0)
                {
                    MessageBoxHelp.ShowMsgWarning("患者信息不存在！");
                    e.Cancel = true;
                    //患者信息清空
                    this.ClearPatientData();
                    return;
                }

                if (datPatientInfo.Rows.Count > 1)
                {
                    PatientSelectForm formPatientSelect = new PatientSelectForm(this.lblOperator.Text, datPatientInfo);
                    formPatientSelect.SelectPatientInfo = this.SetPatientInfo;
                    formPatientSelect.ShowDialog();
                    this.txtDrugID.Focus();
                }
                else
                {
                    //患者信息往画面上设定
                    this.SetPatientInfo(datPatientInfo.Rows[0]);
                }                                              
            }
            catch (Exception ex)
            {
                e.Cancel = true;
                MessageBoxHelp.ShowMsgError("患者信息检索失败!");
                LogManager.WriteLine("患者信息检索失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region txtDrugID_Validating
        /// <summary>
        ///  药品信息Validating
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtDrugID_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                //未发生变化时，取消后续处理
                if (this.txtDrugID.Tag != null && this.txtDrugID.Text == this.txtDrugID.Tag.ToString())
                {
                    return;
                }

                this.errorProvider.Clear();
                //药品信息清空时
                if (string.IsNullOrEmpty(this.txtDrugID.Text))
                {
                    //药品信息清空
                    this.ClearDurgData();
                    //this.errorProvider.SetError(this.txtDrugID, "请输入药品信息");
                    return;
                }

                //药品信息取得
                DataTable datDrugInfo = this.blBillCreate.GetDrugInfo(this.txtDrugID.Text);
                if (datDrugInfo == null || datDrugInfo.Rows.Count == 0)
                {
                    MessageBoxHelp.ShowMsgWarning("药品信息不存在！");
                    e.Cancel = true;
                    this.ClearDurgData();
                    return;
                }

                if (datDrugInfo.Rows.Count > 1)
                {
                    DrugSelectForm formDrugSelect = new DrugSelectForm(this.lblOperator.Text, datDrugInfo);
                    formDrugSelect.SelectDurgInfo=this.SetDrugInfo;
                    formDrugSelect.ShowDialog();
                    this.txtCount.Focus();
                }
                else
                {
                    //药品信息设定
                    this.SetDrugInfo(datDrugInfo.Rows[0]);
                }                
            }
            catch (Exception ex)
            {
                e.Cancel = true;
                MessageBoxHelp.ShowMsgError("药品信息检索失败!");
                LogManager.WriteLine("药品信息检索失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region btnAdd_Click
        /// <summary>
        ///  行追加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                this.errorProvider.Clear();
                //患者信息
                if (string.IsNullOrEmpty(this.txtPatientKey.Text.Trim()))
                {
                    this.errorProvider.SetError(this.txtPatientKey, "请输入患者信息");
                    this.txtPatientKey.Focus();
                    return;
                }

                //药品信息
                if (string.IsNullOrEmpty(this.txtDrugID.Text.Trim()))
                {
                    this.errorProvider.SetError(this.txtDrugID, "请输入药品信息");
                    this.txtDrugID.Focus();
                    return;
                }

                //数量
                int nCount;
                if (string.IsNullOrEmpty(this.txtCount.Text)
                    || !int.TryParse(this.txtCount.Text, out nCount)
                    || nCount <= 0)
                {
                    this.errorProvider.SetError(this.txtCount, "请正确输入数量");
                    this.txtCount.Focus();
                    return;
                }

                //单据番号
                this.nCurrentBillNo++;
                DataRow row = this.datSource.NewRow();
                //单据号画面表示
                string strBillNo = strDataNowyyyyMMdd + this.nCurrentBillNo.ToString().PadLeft(5, '0');
                row[ConstInfo.COL_BILLNO_GUI] = strBillNo;
                //货号
                row[ConstInfo.COL_ARTNO] = this.lblArtNo.Text;
                //品名
                row[ConstInfo.COL_DRUGNAME] = this.lblDrugName.Text;
                //规格
                row[ConstInfo.COL_DRUGSPEC] = this.lblDrugSpec.Text;
                //单位
                row[ConstInfo.COL_UNIT] = this.lblunit.Text;
                //产地
                row[ConstInfo.COL_PRODUCEAREA] = this.lblProduceArea.Text;
                //数量
                row[ConstInfo.COL_DRUGCOUNT] = nCount;
                //患者姓名
                row[ConstInfo.COL_PATIENT_NAME] = this.lblName.Text;
                //患者住址
                row[ConstInfo.COL_ADDR] = this.lblAddres.Text;
                //备注
                row[ConstInfo.COL_NOTE] = this.txtNote.Text;
                //单据号
                row[ConstInfo.COL_BILLNO] = this.nCurrentBillNo;
                //开票日期
                row[ConstInfo.COL_KPDATE] = this.strDateNow;
                //电话
                //long lTel;
                //if (long.TryParse(this.lblTel.Text, out lTel))
                {
                    row[ConstInfo.COL_MOBILENO] = this.lblTel.Text;
                }

                this.datSource.Rows.Add(row);
                this.datSource.AcceptChanges();
                
                //保存按钮状态
                if (!this.btnSave.Enabled)
                {
                    this.btnSave.Enabled = true;
                }

                //患者信息清空
                this.ClearDurgData();
                this.txtDrugID.Focus();
            }
            catch (Exception ex)
            {
                MessageBoxHelp.ShowMsgError("行追加失败!");
                LogManager.WriteLine("行追加失败失败!Exception={0}", ex);
            }
        }
        #endregion

        #region btnSave_Click
        /// <summary>
        ///  保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.blBillCreate.RegisterBileHistoryInfo(this.datSource, this.lstBillNoGUI, this._operatorID, this.strDateNow))
                {
                    MessageBoxHelp.ShowMsgInfor("保存成功!");
                    foreach (DataRow row in this.datSource.Rows)
                    {
                        string strBillNo = row[ConstInfo.COL_BILLNO_GUI].ToString();
                        if (!lstBillNoGUI.Contains(strBillNo))
                        {
                            lstBillNoGUI.Add(strBillNo);   
                        }                        
                    }


                    this.btnSave.Enabled = false;
                    this.txtPatientKey.Focus();
                }
                else
                {
                    MessageBoxHelp.ShowMsgInfor("没有保存的数据!");
                }
            }
            catch (Exception ex)
            {
                MessageBoxHelp.ShowMsgError("保存失败!");
                LogManager.WriteLine("保存失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region btnDel_Click
        /// <summary>
        ///  行删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                this.errorProvider.Clear();
                if (this.datSource.Rows.Count == 0)
                {
                    this.errorProvider.SetError(this.btnDel, "一览中没有数据，不能行删除");
                    return;
                }

                if (this.datGridList.SelectedRows.Count <= 0)
                {
                    this.errorProvider.SetError(this.btnDel, "请选中行再删除");
                    return;
                }

                for (int nCount = this.datGridList.SelectedRows.Count - 1; nCount >= 0; nCount--)
                {
                    this.datSource.Rows[this.datGridList.SelectedRows[nCount].Index].Delete();
                }
                this.datSource.AcceptChanges();

                if (this.datSource.Rows.Count <= 0)
                {
                    this.btnSave.Enabled = false;
                }
                else
                {
                    this.btnSave.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBoxHelp.ShowMsgError("行删除失败!");
                LogManager.WriteLine("保行删除失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region SetPatientInfo
        /// <summary>
        ///  患者信息情报设定
        /// </summary>
        /// <param name="row"></param>
        private void SetPatientInfo(DataRow row)
        {
            //患者信息
            bool bSamePatientFlg = true;
            if (row[ConstInfo.COL_PATIENT_ID].ToString() != this.strCurOatientID)
            {
                bSamePatientFlg = false;
            }

            //患者变更时候
            if (!bSamePatientFlg)
            {
                this.datSource.Clear();
                this.lstBillNoGUI.Clear();
                this.btnSave.Enabled = false;
            }

            //患者编号
            this.lblNum.Text = row[ConstInfo.COL_NUMBER].ToString();
            //姓名
            this.lblName.Text = row[ConstInfo.COL_PATIENT_NAME].ToString();
            //性别
            this.lblSex.Text = row[ConstInfo.COL_SEX].ToString() == "0" ? "男" : "女";
            //生日
            string strBirth = row[ConstInfo.COL_BIRTHDAY].ToString();
            DateTime datBirth;
            if (!DateTime.TryParse(strBirth, out datBirth))
            {
                //年龄
                this.lblAge.Text = "未知";
            }
            else
            {
                //年龄
                this.lblAge.Text = this.CalAge(datBirth).ToString();
            }

            //电话
            this.lblTel.Text = row[ConstInfo.COL_MOBILENO].ToString();
            //住址
            this.lblAddres.Text = row[ConstInfo.COL_ADDR].ToString();

            this.strCurOatientID = row[ConstInfo.COL_PATIENT_ID].ToString();
        }
        #endregion

        #region SetDrugInfo
        /// <summary>
        ///  药品信息设定
        /// </summary>
        /// <param name="row"></param>
        private void SetDrugInfo(DataRow row)
        {
            //药品名称
            this.lblDrugName.Text = row[ConstInfo.COL_DRUGNAME].ToString();
            //货号
            this.lblArtNo.Text = row[ConstInfo.COL_ARTNO].ToString();
            //单位
            this.lblunit.Text = row[ConstInfo.COL_UNIT].ToString();
            //规格
            this.lblDrugSpec.Text = row[ConstInfo.COL_DRUGSPEC].ToString();
            //产地
            this.lblProduceArea.Text = row[ConstInfo.COL_PRODUCEAREA].ToString();
        } 
        #endregion

        #region ClearPatientData
        /// <summary>
        ///  患者信息数据清空
        /// </summary>
        private void ClearPatientData()
        {
            //患者信息
            this.txtPatientKey.Text = string.Empty;
            this.txtPatientKey.Tag = string.Empty;
            //患者编号
            this.lblNum.Text = string.Empty;
            //姓名
            this.lblName.Text = string.Empty;
            //性别
            this.lblSex.Text = string.Empty;
            //年龄
            this.lblAge.Text = string.Empty;
            //电话
            this.lblTel.Text = string.Empty;
            //住址
            this.lblAddres.Text = string.Empty;
            //当前患者ID
            this.strCurOatientID = string.Empty;

            this.btnSave.Enabled = false;
            this.datSource.Clear();
            this.lstBillNoGUI.Clear();
        }
        #endregion

        #region ClearDurgData
        /// <summary>
        ///  药品信息清空
        /// </summary>
        private void ClearDurgData()
        {
            //药品ID
            this.txtDrugID.Text = string.Empty;
            this.txtDrugID.Tag = string.Empty;
            //药品名称
            this.lblDrugName.Text = string.Empty;
            //货号
            this.lblArtNo.Text = string.Empty;
            //单位
            this.lblunit.Text = string.Empty;
            //规格
            this.lblDrugSpec.Text = string.Empty;
            //产地
            this.lblProduceArea.Text = string.Empty;
            //数量
            this.txtCount.Text = string.Empty;
            //备注
            this.txtNote.Text = string.Empty;
        }
        #endregion

        #region CalAge
        /// <summary>
        ///  年龄计算
        /// </summary>
        /// <param name="dtBirth"></param>
        /// <returns></returns>
        private int CalAge(DateTime dtBirth)
        {
            int age = 0;
            DateTime dtNow = DateTime.Now;
            if (dtNow.Year == dtBirth.Year)
                age = 0;
            else
            {
                age = dtNow.Year - dtBirth.Year;
                if (dtNow.Month < dtBirth.Month
                    || (dtNow.Month == dtBirth.Month && dtNow.Day < dtBirth.Day))
                {
                    age = age - 1;
                }                   
            }
            return age;
        }
        #endregion

        #region btnOperatorSetting_Click
        /// <summary>
        /// 操作员信息设置画面打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOperatorSetting_Click(object sender, EventArgs e)
        {
            OperatorSettingForm frmOperatorSetting =
                new OperatorSettingForm(this._operatorID, this.lblOperator.Text);
            frmOperatorSetting.ShowDialog();
            this.txtPatientKey.Focus();
        } 
        #endregion

        #region BillCreateForm_FormClosing
        /// <summary>
        ///  画面关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BillCreateForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //保存按钮不可用
            if (!this.btnSave.Enabled || this.datSource.Rows.Count == 0)
            {
                return;
            }

            DialogResult result = MessageBoxHelp.ShowMsgQuestionYesNoCancel("出票记录没有保存，是否保存？");
            switch (result)
            {
                case System.Windows.Forms.DialogResult.No:
                    return;
                case System.Windows.Forms.DialogResult.Cancel:
                    e.Cancel = true;
                    return;
                case System.Windows.Forms.DialogResult.Yes:
                    break;
                default:
                    return;
            }

            try
            {
                //保存
                if (this.blBillCreate.RegisterBileHistoryInfo(this.datSource, this.lstBillNoGUI, this._operatorID, this.strDateNow))
                {
                    MessageBoxHelp.ShowMsgInfor("保存成功!");
                }
            }
            catch (Exception ex)
            {
                MessageBoxHelp.ShowMsgError("保存失败!");
                e.Cancel = true;
                LogManager.WriteLine("画面关闭时，保存失败!Exception={0}", ex);
            }
        } 
        #endregion

        #region txtCount_KeyPress
        /// <summary>
        ///  数量的入力控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtCount_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }
        #endregion

        /// <summary>
        /// 开票履历查询画面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHistory_Click(object sender, EventArgs e)
        {
            BillHistoryForm frmBillHistory = new BillHistoryForm(this.lblOperator.Text);
            frmBillHistory.ShowDialog();
        }

        private void btnDrupSetting_VisibleChanged(object sender, EventArgs e)
        {
            if (!this.IsAdmin())
            {
                this.btnOperatorSetting.Location = this.btnDrupSetting.Location;
                this.btnHistory.Location = new Point(this.btnOperatorSetting.Location.X + this.btnOperatorSetting.Width + 8, this.btnHistory.Location.Y);
                this.grpBoxInforSetting.Width -= 100; 
            }
        }

        private void txtPatientKey_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)37)
            {
                e.Handled = true;
            }
        }

        private void radioBtn_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rbtnTemp = sender as RadioButton;
            if (!rbtnTemp.Checked && MessageBoxHelp.ShowMsgQuestionYesNo("更改检索条件将清空画面上的数据，是否继续？") == DialogResult.Yes)
            {
                this.ClearPatientData();
                this.txtPatientKey.Focus();
            }
        }

        private void txtPatientKey_Validated(object sender, EventArgs e)
        {
            this.txtPatientKey.Tag = this.txtPatientKey.Text;
        }

        private void txtDrugID_Validated(object sender, EventArgs e)
        {
            this.txtDrugID.Tag = this.txtDrugID.Text;
        }
    }
}
